﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;

namespace StarControl
{
    class Explosao : God
    {
        int i=0; // Conta frames da explosão
        Point frameSize = new Point(64, 64);
        Point currentFrame = new Point(0, 0);
        Point sheetSize = new Point(5, 5);
        public bool explodindo;
        public bool off;
        private Texture2D textureExplosion;

        public Explosao(Game game)
             : base(game)
        {
           
        }

        public void setConfig(Vector2 position)
        {
            setPosition(position);

            off = false;
            textureExplosion = carregarImagem("Textures/explosionSpriteSheet");
            explodindo = false;

        }

        public void explodir()
        {
            explodindo = true;
        }

        public void update(){
            // Calculo de frames da explosao
            currentFrame.X++;
            i++;
            if (currentFrame.X >= sheetSize.X)
            {
                currentFrame.X = 0;
                currentFrame.Y++;
                if (currentFrame.Y >= sheetSize.Y)
                    currentFrame.Y = 0;
            }
            if (i >= 25)
            {
                explodindo = false;
                off = true;
            }
        }

        public void Draw(GameTime gameTime, SpriteBatch spriteBatch)
        {
            spriteBatch.Begin();
            spriteBatch.Draw(textureExplosion, new Vector2(getPosition().X - textureExplosion.Width,
                                                          getPosition().Y - textureExplosion.Height),
                new Rectangle(currentFrame.X * frameSize.X,
                    currentFrame.Y * frameSize.Y,
                    frameSize.X,
                    frameSize.Y),
            Color.White, 0, Vector2.Zero, 1, SpriteEffects.None, 1);
            spriteBatch.End();
        }
    }
}
